﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Show_DetailM : BasicPage
{
    public DateTime max;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            max = GetMaxDate(Request.QueryString["type"].ToString());
            UnlinkList.DataSource = GetDetail("断站");
            UnlinkList.DataBind();
            PowerList.DataSource = GetDetail("停电");
            PowerList.DataBind();
            WaveList.DataSource = GetDetail("驻波");
            WaveList.DataBind();
        }
    }

    private DataSet GetDetail(string argAlarm)
    {
        string sqlstr = "AB_GetInfo_Pk.GetAlarm";
        OracleParameter[] _params = {
                new OracleParameter("V_Type",OracleType.VarChar,100),
                new OracleParameter("v_County",OracleType.VarChar,20),
                new OracleParameter("v_Cell",OracleType.VarChar,200),
				new OracleParameter("V_Begin",OracleType.VarChar,100),
				new OracleParameter("V_End",OracleType.VarChar,100),
				new OracleParameter("V_Net",OracleType.VarChar,20),
                new OracleParameter("V_IFLike",OracleType.VarChar,2),
				new OracleParameter("resultSet",OracleType.Cursor)
            };
        _params[0].Value = argAlarm;
        _params[1].Value = Request.QueryString["county"].ToString();
        _params[2].Value = Request.QueryString["cell"].ToString();
        _params[3].Value = max.ToString("yyyy-MM-dd");
        _params[4].Value = max.AddDays(1).ToString("yyyy-MM-dd");
        _params[5].Value = Request.QueryString["type"].ToString();
        _params[6].Value = "N";
        _params[7].Direction = ParameterDirection.Output;
        return OracleHelper.ExecuteDataSet(sqlstr, CommandType.StoredProcedure, _params);
    }

    private DateTime GetMaxDate(string argType)
    {
        string date;
        if (argType.Equals("3G"))
        {
            string sqlstr = "SELECT MAX(STARTED) FROM ALARM_TABLE_3G";
            date = OracleHelper.ExecuteScalar(sqlstr, CommandType.Text, null).ToString();
        }
        else
        {
            string sqlstr = "SELECT MAX(ALARM_START_TIME) FROM ALARM_TABLE_2G";
            date = OracleHelper.ExecuteScalar(sqlstr, CommandType.Text, null).ToString();
        }
        return DateTime.Parse(date);
    }
}
